#include "mocktimerservice.h"


MockTimerService::MockTimerService() :
   ITimerService(),
   m_lastRequestedTime(-1)
{
   m_lastRegistredlistener = NULL;
}

/**
 * @brief in mock implementation, we do not fire a real timer, but rather store
 *        the parameters of the last call
 * @param millisec - time in ms that would trigger alarm in real implementation
 * @param listener - object used to notify the event
 */
void MockTimerService::triggerTimeout(int millisec, const TimeoutListener *listener)
{
   m_lastRequestedTime = millisec;
   m_lastRegistredlistener = listener;
}

void MockTimerService::stopTimer()
{
   m_lastRequestedTime = -1;
   m_lastRegistredlistener = NULL;
}

/**
 * @brief behave as if real timer was expired
 */
void MockTimerService::simulateTimeout()
{
   if (m_lastRegistredlistener != NULL)
   {
      m_lastRequestedTime = -1;
      m_lastRegistredlistener->timeout();
   }
   else
   {
      throw QString("no event listener registered");
   }
}
